package js;

import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * Created by zhifu on 2015/3/16.
 */
public class JsFunction {
    @Test
    public void testMathFloor(){
        System.out.print(Math.floor(15.9));
    }

    @Test
    public void testAlertTime() throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date nowDate = simpleDateFormat.parse("2015-3-16 11:45:24");
        Date beginDate = simpleDateFormat.parse("2008-8-8 20:00:00");
        long interval = nowDate.getTime() - beginDate.getTime();
        double day = interval / 1000 / 60 / 60 / 24;
        double dayFloor = Math.floor(day);
        double hour = interval/1000/60/60-(24*dayFloor);
        double hourFloor = Math.floor(hour);
        double minutes = interval/1000/60-60*24*dayFloor-60*hourFloor;
        double minutesFloor = Math.floor(minutes);
        double seconds = interval/1000 - (60*60*24*dayFloor)-60*60*hourFloor-60*minutesFloor;
        long round = Math.round(seconds);
        System.out.print("距离北京奥运会已经过去 "+ dayFloor +" 天 "+hourFloor+" 时 "+minutesFloor+" 分 "+round+" 秒");
    }


}
